package JavaSwing类的学习;

import javax.swing.*;
import java.awt.*;


//单行文本框
public class JTextFieldDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Java文本框组件示例");  //创建Frame窗口
        JPanel jp = new JPanel();  //创建面板
        JTextField textField1 = new JTextField();  //创建文本框
        textField1.setText("普通文本框");  //设置文本框内容
        JTextField textField2 = new JTextField(28);
        textField2.setFont(new Font("楷体",Font.BOLD,16));  //修改字体样式
        textField2.setText("指定长度和字体的文本框");
        JTextField textField3 = new JTextField(30);
        textField3.setText("居中对齐");
        textField3.setHorizontalAlignment(JTextField.CENTER);  //居中对齐
        jp.add(textField1);
        jp.add(textField2);
        jp.add(textField3);
        frame.add(jp);
        frame.setBounds(300,200,400,100);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
